home *** CD-ROM | disk | FTP | other *** search
- function isDef(val) {
- return typeof val != "undefined";
- }
- function isNull(val) {
- return val === null;
- }
- function isArray(val) {
- return isObject(val) && val.constructor == Array;
- }
- function isString(val) {
- return typeof val == "string";
- }
- function isBoolean(val) {
- return typeof val == "boolean";
- }
- function isNumber(val) {
- return typeof val == "number";
- }
- function isFunction(val) {
- return typeof val == "function";
- }
- function isObject(val) {
- return val && typeof val == "object";
- }
- function getObjectProps(obj) {
- var ret = [];
- for (var p in obj) {
- ret.push(p);
- }
- return ret;
- }
- function isEmptyObject(val) {
- if (!isObject(val)) {
- return false;
- }
- for (var p in val) {
- return false;
- }
- return true;
- }
- var getHashCode;
- var removeHashCode;
- (function () {
- var hashCodeProperty = "lang_hashCode_";
- getHashCode = function(obj) {
- if (!obj[hashCodeProperty]) {
- obj[hashCodeProperty] = ++getHashCode.hashCodeCounter_;
- }
- return obj[hashCodeProperty];
- };
- removeHashCode = function(obj) {
- obj[hashCodeProperty] = undefined;
- };
- getHashCode.hashCodeCounter_ = 0;
- })();
- String.prototype.startsWith = function(prefix) {
- if (this.length < prefix.length) {
- return false;
- }
- if (this.substring(0, prefix.length) == prefix) {
- return true;
- }
- return false;
- }
- String.prototype.trim = function() {
- return this.replace(/^\s+|\s+$/g, "");
- }
- String.prototype.subs = function() {
- var ret = this;
- for (var i = 0; i < arguments.length; i++) {
- ret = ret.replace(/\%s/, String(arguments[i]));
- }
- return ret;
- }
- if (!Function.prototype.apply) {
- Function.prototype.apply = function(oScope, args) {
- var sarg = [];
- var rtrn, call;
- if (!oScope) oScope = window;
- if (!args) args = [];
- for (var i = 0; i < args.length; i++) {
- sarg[i] = "args[" + i + "]";
- }
- call = "oScope.__applyTemp__.peek().(" + sarg.join(",") + ");";
- if (!oScope.__applyTemp__) {
- oScope.__applyTemp__ = [];
- }
- oScope.__applyTemp__.push(this);
- rtrn = eval(call);
- oScope.__applyTemp__.pop();
- return rtrn;
- }
- }
- if (!Array.prototype.push) {
- Array.prototype.push = function() {
- for (var i = 0; i < arguments.length; i++) {
- this[this.length] = arguments[i];
- }
- return this.length;
- }
- }
- if (!Array.prototype.pop) {
- Array.prototype.pop = function() {
- if (!this.length) {
- return;
- }
- var val = this[this.length - 1];
- this.length--;
- return val;
- }
- }
- Array.prototype.peek = function() {
- return this[this.length - 1];
- }
- if (!Array.prototype.shift) {
- Array.prototype.shift = function() {
- if (this.length == 0) {
- return; // return undefined
- }
- var val = this[0];
- for (var i = 0; i < this.length - 1; i++) {
- this[i] = this[i+1];
- }
- this.length--;
- return val;
- }
- }
- if (!Array.prototype.unshift) {
- Array.prototype.unshift = function() {
- var numArgs = arguments.length;
- for (var i = this.length - 1; i >= 0; i--) {
- this[i + numArgs] = this[i];
- }
- for (var j = 0; j < numArgs; j++) {
- this[j] = arguments[j];
- }
- return this.length;
- }
- }
- if (!Array.prototype.forEach) {
- Array.prototype.forEach = function(callback, scope) {
- for (var i = 0; i < this.length; i++) {
- callback.apply(scope, [this[i]]);
- }
- }
- }
- function bind(fn, self, opt_args) {
- var boundargs = fn.boundArgs_ || [];
- boundargs = boundargs.concat(Array.prototype.slice.call(arguments, 2));
- if (typeof fn.boundSelf_ != "undefined") {
- self = fn.boundSelf_;
- }
- if (typeof fn.foundFn_ != "undefined") {
- fn = fn.boundFn_;
- }
- var newfn = function() {
- var args = boundargs.concat(Array.prototype.slice.call(arguments));
- return fn.apply(self, args);
- }
- newfn.boundArgs_ = boundargs;
- newfn.boundSelf_ = self;
- newfn.boundFn_ = fn;
- return newfn;
- }
- Function.prototype.bind = function(self, opt_args) {
- return bind.apply(
- null, [this, self].concat(Array.prototype.slice.call(arguments, 1)));
- }
- function partial(fn, opt_args) {
- return bind.apply(
- null, [fn, null].concat(Array.prototype.slice.call(arguments, 1)));
- }
- Function.prototype.partial = function(opt_args) {
- return bind.apply(
- null, [this, null].concat(Array.prototype.slice.call(arguments)));
- }
- function bindMethods(obj) {
- for (var p in obj) {
- if (isFunction(obj[p])) {
- obj[p] = obj[p].bind(obj);
- }
- }
- }
- Function.prototype.inherits = function(parentCtor) {
- var tempCtor = function(){};
- tempCtor.prototype = parentCtor.prototype;
- this.superClass_ = parentCtor.prototype;
- this.prototype = new tempCtor();
- }
- Function.prototype.mixin = function(props) {
- for (var x in props) {
- this.prototype[x] = props[x];
- }
- if (isFunction(props['toString']) &&
- props['toString'] != this.prototype['toString']) {
- this.prototype.toString = props.toString
- }
- }
-